feat(power): add Wake-on-LAN power module (type: wol)#217
Open
Ulrond wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Wake-on-LAN (WoL) “power switch” implementation and wires it into the existing powerControlClass dispatch so RAFT can wake devices that are asleep/soft-off via a WoL magic packet.
Changes:
- Added
powerWolmodule that constructs and sends a WoL magic packet to a configurable broadcast address/UDP port. - Added
type == "wol"dispatch branch inpowerControlClassto instantiate the new module.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| framework/core/powerModules/wol.py | Implements WoL magic-packet creation and UDP broadcast send; includes wake-only semantics for powerOff()/reboot(). |
| framework/core/powerControl.py | Adds import and type: "wol" dispatch branch to construct powerWol. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| raise ValueError("powerWol requires a 'mac' address") | ||
| self.mac = mac | ||
| self.broadcast = broadcast or "255.255.255.255" | ||
| self.port = int(port) if port else 9 |
| self.log.info("powerWol(mac={}, broadcast={}, port={})".format( | ||
| self.mac, self.broadcast, self.port)) | ||
|
|
||
| def _magicPacket(self): |
Comment on lines
+72
to
+75
| hexMac = self.mac.replace(":", "").replace("-", "").replace(".", "") | ||
| if len(hexMac) != 12: | ||
| raise ValueError("Invalid MAC address: {}".format(self.mac)) | ||
| return b"\xff" * 6 + bytes.fromhex(hexMac) * 16 |
| bool: True if the packet was sent, False on error. | ||
| """ | ||
| try: | ||
| packet = self._magicPacket() |
powerControlClass had no way to wake a device that is asleep or in a Wake-on-LAN soft-off state. Add framework/core/powerModules/wol.py (powerWol) and a `type: "wol"` dispatch branch: - powerOn() sends the WoL magic packet (6x 0xFF + MAC x16) to broadcast:port. - Wake-on-LAN is wake-only: powerOff() is a logged no-op, reboot() a best-effort wake. - Config: mac (required), broadcast (default 255.255.255.255), port (default 9). - Standard-library only (socket); no new dependencies. Fixes rdkcentral#216
c5d9760 to
0a32b41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #216.
What
Adds
framework/core/powerModules/wol.py(powerWol) and atype: "wol"branch inpowerControlClass, so RAFT can wake a device that is asleep or in a Wake-on-LAN soft-off state.powerOn()sends the WoL magic packet (6x0xFF+ target MAC x16) tobroadcast:port.powerOff()is a logged no-op andreboot()is a best-effort wake.powerSwitch:):mac(required),broadcast(default255.255.255.255),port(default9).socket) — no new dependencies.Why
powerControlClasssupports hs100 / apc / apcAos / olimex / kasa / tapo / SLP / none, but none can bring back a target that has dropped its console to sleep. Targets that aggressively deep-sleep can only be woken by a magic packet; without this, runs against them need an out-of-band wake step before the session opens.Testing
powerOn()builds a correct magic packet and woke a real armv7 target on the same broadcast domain.powerOff()/reboot()behave as documented (no-op / best-effort wake).powerControldispatch (type: "wol") constructs the module; both files pass a syntax check.